package ThreadDemo;

/*
 * Author: JacksonCoder
 * FileName: CompletableFutureChainExample
 * Version: 1.0.0
 * Date: 2025/2/21
 */

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

public class CompletableFutureChainExample {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CompletableFuture.supplyAsync(() -> {
            try {
                Thread.sleep(1000);// 模拟耗时操作
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return "Hello";
        }).thenApplyAsync(result -> {
            return result + "World";
        }).thenAcceptAsync(result -> {
            System.out.println(result);  // 输出 "hello world"
        }).get();   // 等待所有任务完成a
    }

}
